package cn.wolfcode.wms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IPermissionService;
import cn.wolfcode.wms.util.JsonResult;
import cn.wolfcode.wms.util.RequiredPermission;

@Controller
@RequestMapping("/permission")
public class PermissionController {
	@Autowired
	private IPermissionService service;
	@RequiredPermission("权限列表")
	@RequestMapping("/list")
	public String list(Model model,QueryObject qo){
		model.addAttribute("result", service.query(qo));
		return "permission/list";
	}
	@RequiredPermission("权限删除")
	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Long id){
		JsonResult result = new JsonResult();
		try {
			if (id!=null) {
				service.delete(id);
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("删除失败");
		}
		return result;
	}
	@RequiredPermission("权限加载")
	@RequestMapping("/load")
	@ResponseBody
	public JsonResult load(){
		JsonResult result = new JsonResult();
		try {
			service.load();
		} catch (Exception e) {
			e.printStackTrace();
			result.markMsg("加载失败");
		}
		return result;
	}
}
